//
// Cryptographic Unit Tests - for about everything that can go wrong wrt linking
//
// Authors:
//	Sebastien Pouliot  <sebastien@xamarin.com>
//
// Copyright 2012 Xamarin Inc.
//

using System.Linq;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using MonoTests.System.Net.Http;

namespace LinkSdk {

	[TestFixture]
	// we want the test to be availble if we use the linker
	[Preserve (AllMembers = true)]
	public class CryptoTest {

		[Test]
		public void AesCreate ()
		{
			// Aes resides in mscorlib.dll but needs to create instance of types that are
			// located inside System.Core.dll - IOW the linker needs to be aware of this
			Aes aes = Aes.Create ();
			Assert.NotNull (aes, "Aes");
			const string prefix = "System.Security.Cryptography, ";
			Assert.That (aes.GetType ().Assembly.FullName, Does.StartWith (prefix), prefix);
		}

		static int trust_validation_callback;

		[Test]
		public void TrustUsingNewCallback ()
		{
			// Three similar tests exists in dontlink, linkall and linksdk to test 3 different cases
			// untrusted, custom ICertificatePolicy and ServerCertificateValidationCallback without
			// having caching issues (in S.Net or the SSL handshake cache)
			try {
				ServicePointManager.ServerCertificateValidationCallback = delegate (object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors errors)
				{
					Assert.That (errors, Is.EqualTo (SslPolicyErrors.None), "certificateProblem");
					X509Certificate2 c2 = X509CertificateLoader.LoadCertificate (cert.GetRawCertData ());
					Assert.True (chain.Build (c2), "Build");
					trust_validation_callback++;
					return true;
				};
				WebClient wc = new WebClient ();
				Assert.IsNotNull (wc.DownloadString (NetworkResources.XamarinUrl));
				// caching means it will be called at least for the first run, but it might not
				// be called again in subsequent requests (unless it expires)
				Assert.That (trust_validation_callback, Is.GreaterThan (0), "validation done");
			} catch (WebException we) {
				TestRuntime.IgnoreInCIIfBadNetwork (we);
				throw;
			} finally {
				ServicePointManager.ServerCertificateValidationCallback = null;
			}
		}

		[Test]
		public void SSL_IP_5706 ()
		{
			WebClient wc = new WebClient ();

			// IP are (generally) not allowed
			foreach (var ip in Dns.GetHostAddresses ("www.google.com")) {
				if (ip.AddressFamily != System.Net.Sockets.AddressFamily.InterNetwork)
					continue;

				Assert.Throws<WebException> (delegate
				{
					wc.DownloadString ("https://" + ip.ToString ());
				}, ip.ToString ());
				return; // checking a single IP is enough to prove the point
			}
		}

		static int sne_validation_callback;

		[Test]
		public void TLS1_ServerNameExtension ()
		{
			// without support for the "server_name" TLS extension (RFC3546) we receive the "general"
			// certificate of a server, which might not be the right one if a single server instance
			// is used for many hosts (without a common name)

			// note: SSLv3 won't work, test is inside linkall.app (due to result caching)

			var actual = ServicePointManager.SecurityProtocol;
			try {
				ServicePointManager.ServerCertificateValidationCallback = delegate (object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors errors)
				{
					Assert.That (errors, Is.EqualTo (SslPolicyErrors.None), "certificateProblem");
					X509Certificate2 c2 = X509CertificateLoader.LoadCertificate (cert.GetRawCertData ());
					Assert.True (chain.Build (c2), "Build");
					sne_validation_callback++;
					return true;
				};
				ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
				WebClient wc = new WebClient ();
				Assert.IsNotNull (wc.DownloadString (NetworkResources.StatsUrl));
			} catch (WebException we) {
				// failing to get data does not mean the SSL/TLS session was not established
				if (sne_validation_callback == 0) {
					TestRuntime.IgnoreInCIIfBadNetwork (we);
					throw;
				}
			} finally {
				ServicePointManager.ServerCertificateValidationCallback = null;
				ServicePointManager.SecurityProtocol = actual;
			}
			// caching means it will be called at least for the first run, but it might not
			// be called again in subsequent requests (unless it expires)
			Assert.That (sne_validation_callback, Is.GreaterThan (0), "validation done");
		}

		[Test]
		public void Chain ()
		{
			string certString = "MIIDGjCCAgKgAwIBAgICApowDQYJKoZIhvcNAQEFBQAwLjELMAkGA1UEBhMCQ1oxDjAMBgNVBAoTBVJlYmV4MQ8wDQYDVQQDEwZUZXN0Q0EwHhcNMDAwMTAxMDAwMDAwWhcNNDkxMjMxMDAwMDAwWjAuMQswCQYDVQQGEwJDWjEOMAwGA1UEChMFUmViZXgxDzANBgNVBAMTBlRlc3RDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMgeRAcaNLTFaaBhFx8RDJ8b9K655dNUXmO11mbImDbPq4qVeZXDgAjnzPov8iBscwfqBvBpF38LsxBIPA2i1d0RMsQruOhJHttA9I0enElUXXj63sOEVNMSQeg1IMyvNeEotag+Gcx6SF+HYnariublETaZGzwAOD2SM49mfqUyfkgeTjdO6qp8xnoEr7dS5pEBHDg70byj/JEeZd3gFea9TiOXhbCrI89dKeWYBeoHFYhhkaSB7q9EOaUEzKo/BQ6PBHFu6odfGkOjXuwfPkY/wUy9U4uj75LmdhzvJf6ifsJS9BQZF4//JcUYSxiyzpxDYqSbTF3g9w5Ds2LOAscCAwEAAaNCMEAwDgYDVR0PAQH/BAQDAgB/MA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFD1v20tPgvHTEK/0eLO09j0rL2qXMA0GCSqGSIb3DQEBBQUAA4IBAQAZIjcdR3EZiFJ67gfCnPBrxVgFNvaRAMCYEYYIGDCAUeB4bLTu9dvun9KFhgVNqjgx+xTTpx9d/5mAZx5W3YAG6faQPCaHccLefB1M1hVPmo8md2uw1a44RHU9LlM0V5Lw8xTKRkQiZz3Ysu0sY27RvLrTptbbfkE4Rp9qAMguZT9cFrgPAzh+0zuo8NNj9Jz7/SSa83yIFmflCsHYSuNyKIy2iaX9TCVbTrwJmRIB65gqtTb6AKtFGIPzsb6nayHvgGHFchrFovcNrvRpE71F38oVG+eCjT23JfiIZim+yJLppSf56167u8etDcQ39j2b9kzWlHIVkVM0REpsKF7S";
			X509Certificate2 rootCert = X509CertificateLoader.LoadCertificate (Convert.FromBase64String (certString));

			byte [] certData = new byte [] { 0x30, 0x82, 0x02, 0xFA, 0x30, 0x82, 0x01, 0xE2, 0xA0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x03, 0x01, 0x4F, 0x55, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x2E, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x43, 0x5A, 0x31, 0x0E, 0x30, 0x0C, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x13, 0x05, 0x52, 0x65, 0x62, 0x65, 0x78, 0x31, 0x0F, 0x30, 0x0D, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x06, 0x54, 0x65, 0x73, 0x74, 0x43, 0x41, 0x30, 0x1E, 0x17, 0x0D, 0x31, 0x32, 0x30, 0x34, 0x32, 0x32, 0x31, 0x38, 0x33, 0x31, 0x35, 0x33, 0x5A, 0x17, 0x0D, 0x34, 0x39, 0x31, 0x32, 0x33, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x5A, 0x30, 0x37, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x43, 0x5A, 0x31, 0x0E, 0x30, 0x0C, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x13, 0x05, 0x52, 0x65, 0x62, 0x65, 0x78, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x0F, 0x77, 0x69, 0x6E, 0x30, 0x31, 0x2E, 0x64, 0x30, 0x35, 0x2E, 0x6C, 0x6F, 0x63, 0x61, 0x6C, 0x30, 0x81, 0x9F, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8D, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xF1, 0x4F, 0xAC, 0x71, 0x70, 0x8F, 0x8A, 0xFE, 0x38, 0x67, 0xA7, 0x21, 0x56, 0x8B, 0x34, 0xBC, 0xF5, 0xCD, 0x48, 0x1C, 0x69, 0xEB, 0x83, 0x98, 0x69, 0x3D, 0x33, 0x2A, 0x7B, 0x04, 0xB1, 0x0A, 0xA9, 0x2C, 0x17, 0xDD, 0x41, 0xEC, 0x21, 0x91, 0xB8, 0x12, 0x95, 0xB0, 0x4C, 0x2A, 0x53, 0xBF, 0x06, 0x47, 0x72, 0xBB, 0x68, 0xCA, 0x49, 0x34, 0x15, 0x7B, 0x78, 0x4F, 0x42, 0x03, 0xD9, 0x58, 0xEE, 0x9D, 0x72, 0x61, 0xAD, 0xAD, 0x0C, 0x28, 0x65, 0x61, 0x48, 0xF8, 0x68, 0xB5, 0x16, 0x19, 0xD0, 0xDD, 0x47, 0x44, 0x86, 0xE3, 0xA6, 0x93, 0x81, 0xD5, 0xA1, 0x70, 0x23, 0x05, 0x74, 0x33, 0xD1, 0xD2, 0x21, 0x17, 0x68, 0xAF, 0x5F, 0x25, 0xD5, 0x8C, 0x72, 0xF6, 0x28, 0xF4, 0x1F, 0x42, 0x24, 0xCF, 0x18, 0x7B, 0x5D, 0xCE, 0x29, 0x43, 0xF2, 0x10, 0xB6, 0x73, 0x65, 0x4C, 0x0A, 0x17, 0x02, 0x03, 0x01, 0x00, 0x01, 0xA3, 0x81, 0x9B, 0x30, 0x81, 0x98, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x1D, 0x0F, 0x01, 0x01, 0xFF, 0x04, 0x04, 0x03, 0x02, 0x05, 0xA0, 0x30, 0x1D, 0x06, 0x03, 0x55, 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0x14, 0x00, 0x58, 0x48, 0x55, 0x6C, 0x45, 0xC6, 0xCC, 0x06, 0x25, 0x2D, 0xD3, 0xBA, 0x0C, 0x08, 0x81, 0x00, 0x58, 0xDF, 0x30, 0x13, 0x06, 0x03, 0x55, 0x1D, 0x25, 0x04, 0x0C, 0x30, 0x0A, 0x06, 0x08, 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01, 0x30, 0x1F, 0x06, 0x03, 0x55, 0x1D, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x3D, 0x6F, 0xDB, 0x4B, 0x4F, 0x82, 0xF1, 0xD3, 0x10, 0xAF, 0xF4, 0x78, 0xB3, 0xB4, 0xF6, 0x3D, 0x2B, 0x2F, 0x6A, 0x97, 0x30, 0x31, 0x06, 0x03, 0x55, 0x1D, 0x1F, 0x04, 0x2A, 0x30, 0x28, 0x30, 0x26, 0xA0, 0x24, 0xA0, 0x22, 0x86, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x74, 0x65, 0x73, 0x74, 0x2D, 0x63, 0x61, 0x2E, 0x6C, 0x6F, 0x63, 0x61, 0x6C, 0x2F, 0x74, 0x65, 0x73, 0x74, 0x2D, 0x63, 0x61, 0x2E, 0x63, 0x72, 0x6C, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x22, 0x48, 0xC3, 0x95, 0x3A, 0x51, 0x72, 0x15, 0x41, 0x5B, 0x47, 0xC4, 0xC5, 0x4E, 0x2E, 0x97, 0xAC, 0x1D, 0x0B, 0xD1, 0xA4, 0x38, 0xF2, 0xFB, 0x6E, 0x33, 0x9D, 0xC8, 0x93, 0x4C, 0x88, 0x34, 0xA3, 0x68, 0xC7, 0xC6, 0x42, 0x51, 0x54, 0x31, 0x72, 0x72, 0xEB, 0xEE, 0x5C, 0xF0, 0x7D, 0xC9, 0xC8, 0xAE, 0x24, 0x9F, 0xA0, 0x1D, 0x2E, 0xEE, 0x84, 0x55, 0xC3, 0x3A, 0xC4, 0xCE, 0xE1, 0xB3, 0xA2, 0xD2, 0x1F, 0x44, 0xC8, 0x81, 0x0F, 0x9C, 0xED, 0x5B, 0x17, 0xBB, 0x2C, 0xDA, 0x4A, 0x9D, 0xF7, 0x7D, 0x5A, 0x08, 0x6C, 0xA3, 0xF4, 0xCB, 0x55, 0xE6, 0x1A, 0xAA, 0xC7, 0x14, 0x16, 0x7D, 0x46, 0xD0, 0x7C, 0x71, 0xA8, 0xA7, 0xEA, 0xBF, 0xA6, 0x92, 0xD4, 0xC5, 0x7A, 0xB8, 0x45, 0x3A, 0x00, 0xB3, 0xDC, 0x76, 0x2E, 0xEB, 0xB9, 0xF4, 0x6B, 0xDC, 0xF2, 0xC4, 0x7C, 0x0C, 0xD5, 0x1C, 0x73, 0xE8, 0xE1, 0xBB, 0xC1, 0x5C, 0xCC, 0xD9, 0xBE, 0xDE, 0x61, 0x4D, 0xEF, 0x2B, 0x23, 0xFA, 0xA6, 0xF6, 0xED, 0x4F, 0x5F, 0x2C, 0xCA, 0x68, 0x29, 0x59, 0x27, 0x82, 0x41, 0x5E, 0xAD, 0xC8, 0x93, 0xBF, 0x83, 0x01, 0x8F, 0x32, 0xCB, 0x79, 0xEE, 0x93, 0x4C, 0xCB, 0x87, 0x48, 0x62, 0x0D, 0x44, 0xD7, 0x80, 0x31, 0x87, 0x41, 0x72, 0x2D, 0x12, 0xA0, 0x2C, 0x99, 0x89, 0x08, 0x5F, 0xE9, 0xFE, 0x5E, 0xB4, 0xEC, 0xCB, 0x6C, 0x23, 0xC1, 0xB8, 0xE4, 0xD6, 0x1E, 0x4B, 0x9C, 0x88, 0x0A, 0x63, 0x65, 0x78, 0xC0, 0x37, 0xAC, 0x54, 0xCB, 0xDE, 0xA9, 0x0F, 0x59, 0x43, 0x1E, 0x41, 0xF5, 0x32, 0xAC, 0x85, 0x69, 0xE9, 0xBA, 0xA6, 0x78, 0x87, 0x88, 0x8B, 0x71, 0xFB, 0xE4, 0x51, 0xC0, 0xF5, 0xB7, 0x4C, 0x1F, 0xCF, 0x6A, 0x1C, 0xF6, 0x1B, 0x27, 0x50, 0xE9, 0xAC, 0xBF, 0xB7, 0x4E };

			X509Certificate2 cert = X509CertificateLoader.LoadCertificate (certData);
			X509Chain chain = new X509Chain (false);

			chain.ChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust;
			chain.ChainPolicy.CustomTrustStore.Add (rootCert);

			Assert.False (chain.Build (cert), "Online");
			Assert.True (chain.ChainStatus.Any (s => s.Status.HasFlag (X509ChainStatusFlags.RevocationStatusUnknown)), "Online");

			chain.ChainPolicy.RevocationMode = X509RevocationMode.Offline;
			Assert.False (chain.Build (cert), "Offline");
			Assert.True (chain.ChainStatus.Any (s => s.Status.HasFlag (X509ChainStatusFlags.RevocationStatusUnknown)), "Offline");

			chain.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck;
			Assert.True (chain.Build (cert), "NoCheck");
			Assert.AreEqual (0, chain.ChainStatus.Length, "NoCheck");
		}

		byte [] sha256_data = {
			0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x42, 0x45, 0x47, 0x49, 0x4E, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49, 0x46, 0x49, 0x43, 0x41,
			0x54, 0x45, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x0D, 0x0A, 0x4D, 0x49, 0x49, 0x43, 0x78, 0x44, 0x43, 0x43, 0x41, 0x61, 0x79,
			0x67, 0x41, 0x77, 0x49, 0x42, 0x41, 0x67, 0x49, 0x44, 0x41, 0x4B, 0x37, 0x6C, 0x4D, 0x41, 0x30, 0x47, 0x43, 0x53, 0x71,
			0x47, 0x53, 0x49, 0x62, 0x33, 0x44, 0x51, 0x45, 0x42, 0x43, 0x77, 0x55, 0x41, 0x4D, 0x43, 0x34, 0x78, 0x43, 0x7A, 0x41,
			0x4A, 0x42, 0x67, 0x4E, 0x56, 0x42, 0x41, 0x59, 0x54, 0x41, 0x6B, 0x4E, 0x61, 0x0D, 0x0A, 0x4D, 0x51, 0x34, 0x77, 0x44,
			0x41, 0x59, 0x44, 0x56, 0x51, 0x51, 0x4B, 0x45, 0x77, 0x56, 0x53, 0x5A, 0x57, 0x4A, 0x6C, 0x65, 0x44, 0x45, 0x50, 0x4D,
			0x41, 0x30, 0x47, 0x41, 0x31, 0x55, 0x45, 0x41, 0x78, 0x4D, 0x47, 0x56, 0x47, 0x56, 0x7A, 0x64, 0x45, 0x4E, 0x42, 0x4D,
			0x42, 0x34, 0x58, 0x44, 0x54, 0x45, 0x7A, 0x4D, 0x44, 0x55, 0x78, 0x4F, 0x54, 0x45, 0x79, 0x4E, 0x44, 0x63, 0x31, 0x0D,
			0x0A, 0x4E, 0x31, 0x6F, 0x58, 0x44, 0x54, 0x51, 0x35, 0x4D, 0x54, 0x49, 0x7A, 0x4D, 0x54, 0x41, 0x77, 0x4D, 0x44, 0x41,
			0x77, 0x4D, 0x46, 0x6F, 0x77, 0x4F, 0x6A, 0x45, 0x57, 0x4D, 0x42, 0x51, 0x47, 0x41, 0x31, 0x55, 0x45, 0x41, 0x78, 0x4D,
			0x4E, 0x55, 0x6D, 0x56, 0x69, 0x5A, 0x58, 0x67, 0x67, 0x55, 0x33, 0x56, 0x77, 0x63, 0x47, 0x39, 0x79, 0x64, 0x44, 0x45,
			0x67, 0x4D, 0x42, 0x34, 0x47, 0x0D, 0x0A, 0x43, 0x53, 0x71, 0x47, 0x53, 0x49, 0x62, 0x33, 0x44, 0x51, 0x45, 0x4A, 0x41,
			0x52, 0x59, 0x52, 0x63, 0x33, 0x56, 0x77, 0x63, 0x47, 0x39, 0x79, 0x64, 0x45, 0x42, 0x79, 0x5A, 0x57, 0x4A, 0x6C, 0x65,
			0x43, 0x35, 0x75, 0x5A, 0x58, 0x51, 0x77, 0x67, 0x5A, 0x38, 0x77, 0x44, 0x51, 0x59, 0x4A, 0x4B, 0x6F, 0x5A, 0x49, 0x68,
			0x76, 0x63, 0x4E, 0x41, 0x51, 0x45, 0x42, 0x42, 0x51, 0x41, 0x44, 0x0D, 0x0A, 0x67, 0x59, 0x30, 0x41, 0x4D, 0x49, 0x47,
			0x4A, 0x41, 0x6F, 0x47, 0x42, 0x41, 0x4B, 0x7A, 0x36, 0x49, 0x37, 0x49, 0x59, 0x4E, 0x4A, 0x4C, 0x44, 0x43, 0x36, 0x42,
			0x79, 0x44, 0x32, 0x75, 0x59, 0x36, 0x69, 0x55, 0x61, 0x34, 0x30, 0x54, 0x34, 0x37, 0x34, 0x44, 0x41, 0x65, 0x59, 0x55,
			0x49, 0x31, 0x37, 0x43, 0x79, 0x39, 0x55, 0x6B, 0x77, 0x62, 0x4E, 0x4D, 0x2B, 0x6B, 0x39, 0x62, 0x57, 0x0D, 0x0A, 0x68,
			0x75, 0x46, 0x62, 0x65, 0x63, 0x56, 0x42, 0x6D, 0x43, 0x37, 0x42, 0x79, 0x31, 0x6C, 0x48, 0x65, 0x2B, 0x79, 0x41, 0x59,
			0x59, 0x78, 0x78, 0x74, 0x47, 0x50, 0x7A, 0x41, 0x48, 0x58, 0x50, 0x76, 0x68, 0x4A, 0x4D, 0x56, 0x50, 0x41, 0x2F, 0x37,
			0x4C, 0x36, 0x41, 0x4B, 0x58, 0x6D, 0x6A, 0x71, 0x69, 0x77, 0x78, 0x7A, 0x47, 0x51, 0x79, 0x30, 0x73, 0x59, 0x67, 0x2F,
			0x6A, 0x36, 0x79, 0x0D, 0x0A, 0x6F, 0x58, 0x39, 0x36, 0x39, 0x52, 0x53, 0x30, 0x49, 0x58, 0x33, 0x75, 0x33, 0x64, 0x31,
			0x72, 0x35, 0x61, 0x6F, 0x44, 0x76, 0x36, 0x4A, 0x58, 0x53, 0x69, 0x53, 0x73, 0x75, 0x67, 0x78, 0x56, 0x47, 0x69, 0x65,
			0x54, 0x53, 0x2F, 0x50, 0x71, 0x55, 0x6E, 0x6E, 0x76, 0x72, 0x49, 0x74, 0x59, 0x78, 0x6F, 0x64, 0x4F, 0x31, 0x58, 0x79,
			0x76, 0x41, 0x67, 0x4D, 0x42, 0x41, 0x41, 0x47, 0x6A, 0x0D, 0x0A, 0x59, 0x7A, 0x42, 0x68, 0x4D, 0x41, 0x34, 0x47, 0x41,
			0x31, 0x55, 0x64, 0x44, 0x77, 0x45, 0x42, 0x2F, 0x77, 0x51, 0x45, 0x41, 0x77, 0x49, 0x45, 0x38, 0x44, 0x41, 0x64, 0x42,
			0x67, 0x4E, 0x56, 0x48, 0x51, 0x34, 0x45, 0x46, 0x67, 0x51, 0x55, 0x66, 0x75, 0x52, 0x51, 0x78, 0x4E, 0x75, 0x59, 0x71,
			0x77, 0x73, 0x38, 0x56, 0x48, 0x7A, 0x4A, 0x6D, 0x4A, 0x50, 0x6F, 0x39, 0x41, 0x45, 0x6F, 0x0D, 0x0A, 0x6F, 0x50, 0x77,
			0x77, 0x44, 0x77, 0x59, 0x44, 0x56, 0x52, 0x30, 0x6C, 0x42, 0x41, 0x67, 0x77, 0x42, 0x67, 0x59, 0x45, 0x56, 0x52, 0x30,
			0x6C, 0x41, 0x44, 0x41, 0x66, 0x42, 0x67, 0x4E, 0x56, 0x48, 0x53, 0x4D, 0x45, 0x47, 0x44, 0x41, 0x57, 0x67, 0x42, 0x51,
			0x39, 0x62, 0x39, 0x74, 0x4C, 0x54, 0x34, 0x4C, 0x78, 0x30, 0x78, 0x43, 0x76, 0x39, 0x48, 0x69, 0x7A, 0x74, 0x50, 0x59,
			0x39, 0x0D, 0x0A, 0x4B, 0x79, 0x39, 0x71, 0x6C, 0x7A, 0x41, 0x4E, 0x42, 0x67, 0x6B, 0x71, 0x68, 0x6B, 0x69, 0x47, 0x39,
			0x77, 0x30, 0x42, 0x41, 0x51, 0x73, 0x46, 0x41, 0x41, 0x4F, 0x43, 0x41, 0x51, 0x45, 0x41, 0x41, 0x59, 0x62, 0x69, 0x46,
			0x41, 0x6D, 0x33, 0x6E, 0x71, 0x61, 0x6F, 0x4A, 0x51, 0x45, 0x41, 0x6D, 0x37, 0x7A, 0x34, 0x33, 0x71, 0x6E, 0x71, 0x41,
			0x6B, 0x41, 0x6E, 0x35, 0x30, 0x76, 0x6F, 0x0D, 0x0A, 0x75, 0x4F, 0x39, 0x4E, 0x57, 0x61, 0x33, 0x53, 0x43, 0x45, 0x38,
			0x78, 0x6B, 0x4C, 0x55, 0x2B, 0x31, 0x50, 0x62, 0x67, 0x76, 0x6F, 0x48, 0x4E, 0x50, 0x54, 0x6A, 0x36, 0x4D, 0x51, 0x30,
			0x59, 0x37, 0x6F, 0x63, 0x2B, 0x6D, 0x42, 0x75, 0x55, 0x6B, 0x5A, 0x52, 0x63, 0x4B, 0x33, 0x51, 0x4C, 0x69, 0x58, 0x6C,
			0x62, 0x34, 0x66, 0x6E, 0x7A, 0x39, 0x59, 0x55, 0x36, 0x66, 0x69, 0x7A, 0x4A, 0x0D, 0x0A, 0x79, 0x6A, 0x33, 0x76, 0x33,
			0x42, 0x34, 0x6B, 0x4A, 0x33, 0x5A, 0x62, 0x42, 0x6D, 0x38, 0x48, 0x4E, 0x34, 0x78, 0x79, 0x44, 0x62, 0x66, 0x6E, 0x77,
			0x6C, 0x67, 0x42, 0x55, 0x65, 0x6F, 0x68, 0x78, 0x61, 0x36, 0x2B, 0x50, 0x78, 0x67, 0x2F, 0x37, 0x72, 0x39, 0x34, 0x78,
			0x54, 0x4A, 0x72, 0x35, 0x46, 0x30, 0x43, 0x68, 0x2F, 0x41, 0x68, 0x2F, 0x6D, 0x59, 0x37, 0x66, 0x4B, 0x6C, 0x50, 0x0D,
			0x0A, 0x46, 0x46, 0x35, 0x47, 0x68, 0x4A, 0x2B, 0x62, 0x34, 0x76, 0x55, 0x6F, 0x36, 0x47, 0x74, 0x6E, 0x79, 0x6F, 0x4F,
			0x33, 0x58, 0x57, 0x4C, 0x45, 0x34, 0x4D, 0x38, 0x4B, 0x67, 0x68, 0x6C, 0x39, 0x78, 0x48, 0x4E, 0x32, 0x52, 0x76, 0x57,
			0x47, 0x45, 0x39, 0x4B, 0x6F, 0x31, 0x4B, 0x31, 0x55, 0x62, 0x42, 0x62, 0x53, 0x4A, 0x51, 0x4D, 0x76, 0x66, 0x65, 0x49,
			0x65, 0x52, 0x38, 0x32, 0x71, 0x0D, 0x0A, 0x69, 0x66, 0x37, 0x49, 0x30, 0x56, 0x2B, 0x77, 0x59, 0x70, 0x57, 0x61, 0x4B,
			0x79, 0x5A, 0x68, 0x33, 0x6C, 0x50, 0x4C, 0x34, 0x33, 0x67, 0x35, 0x4C, 0x4F, 0x42, 0x34, 0x75, 0x51, 0x6C, 0x68, 0x76,
			0x76, 0x50, 0x4D, 0x5A, 0x63, 0x43, 0x48, 0x36, 0x4F, 0x37, 0x37, 0x37, 0x6E, 0x2F, 0x33, 0x4C, 0x2B, 0x54, 0x6C, 0x32,
			0x2F, 0x41, 0x56, 0x31, 0x73, 0x7A, 0x73, 0x67, 0x53, 0x6B, 0x54, 0x0D, 0x0A, 0x47, 0x79, 0x74, 0x54, 0x75, 0x4B, 0x6A,
			0x51, 0x35, 0x6E, 0x50, 0x53, 0x58, 0x76, 0x65, 0x44, 0x39, 0x76, 0x4B, 0x42, 0x50, 0x2F, 0x58, 0x4C, 0x73, 0x54, 0x4D,
			0x75, 0x69, 0x6A, 0x48, 0x4C, 0x43, 0x68, 0x57, 0x55, 0x69, 0x33, 0x74, 0x4B, 0x7A, 0x49, 0x48, 0x6F, 0x66, 0x4B, 0x6F,
			0x58, 0x62, 0x42, 0x43, 0x35, 0x37, 0x77, 0x3D, 0x3D, 0x0D, 0x0A, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x45, 0x4E, 0x44, 0x20,
			0x43, 0x45, 0x52, 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x0D, 0x0A, };


		[Test]
		public void Sha256 ()
		{
			X509Certificate2 c = X509CertificateLoader.LoadCertificate (sha256_data);
			// can't build is fine - as long as we do not throw
			Assert.False (new X509Chain (false).Build (c), "Build");
		}
	}
}
